home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8220 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  87 lines

  1. Path: news-m01.ny.us.ibm.net!usenet
  2. From: schlaep@ibm.net (Patrick Schlaepfer)
  3. Newsgroups: comp.lang.c++
  4. Subject: VC++4.0 & SQL
  5. Date: Thu, 15 Feb 1996 21:25:16 GMT
  6. Message-ID: <4g06hg$4beo@news-s01.ny.us.ibm.net>
  7. NNTP-Posting-Host: slip139-92-42-176.ut.nl.ibm.net
  8. X-Newsreader: Forte Free Agent 1.0.82
  9.  
  10. Source code of the SQL testprogram, copied
  11. from the MS Visual C++ CD.
  12.  
  13. Error Message I get:
  14.  
  15. --------------------Configuration: Text1 - Win32
  16. Debug--------------------
  17. Compiling...
  18. Text1.cpp
  19. C:\home\patrick\msdv\simple_odbc\Text1.cpp(26) : error C2664:
  20. 'SQLConnect' : 
  21. cannot convert parameter 2 from 'char [8]' to 'unsigned char *' (new
  22. behavior; please see help)
  23. Error executing cl.exe.
  24. Text1.obj - 1 error(s), 0 warning(s)
  25.  
  26. What can I do to connect the database? 
  27. Any suggestions.
  28.  
  29. Programname: Text1.cpp
  30.  
  31. #include <windows.h>
  32. #include <sql.h>
  33. #include <sqlext.h>
  34. #include <string.h>
  35.  
  36. void main()
  37. {
  38.     HENV    henv;
  39.     HDBC    hdbc;
  40.     HSTMT   hstmt;
  41.     RETCODE retcode;
  42.  
  43.     retcode = SQLAllocEnv(&henv);              /* Environment handle */
  44.     if (retcode == SQL_SUCCESS) {
  45.         retcode = SQLAllocConnect(henv, &hdbc); /* Connection handle */
  46.         if (retcode == SQL_SUCCESS) {
  47.  
  48.           /* Set login timeout to 5 seconds. */
  49.  
  50.           SQLSetConnectOption(hdbc, SQL_LOGIN_TIMEOUT, 5);
  51.  
  52.           /* Connect to data source */
  53.  
  54.           retcode = SQLConnect(hdbc, "EmpData", SQL_NTS,
  55.                                      "JohnS", SQL_NTS,
  56.                                      "Sesame", SQL_NTS);
  57.  
  58.           if (retcode == SQL_SUCCESS || retcode ==
  59. SQL_SUCCESS_WITH_INFO){
  60.  
  61.                /* Process data after successful connection */
  62.  
  63.                retcode = SQLAllocStmt(hdbc, &hstmt); /* Statement
  64. handle */
  65.                if (retcode == SQL_SUCCESS) {
  66.                     MessageBox(NULL, "Successfully
  67. completed.","Success", MB_OK);
  68.                     SQLFreeStmt(hstmt, SQL_DROP);
  69.                }
  70.                SQLDisconnect(hdbc);
  71.           }
  72.           SQLFreeConnect(hdbc);
  73.      }
  74.      SQLFreeEnv(henv);
  75.     }
  76. }
  77.  
  78.  
  79. Regards Pat
  80. ------------------------------------------------
  81.     _/   _/  _/_/_/     Patrick Schlaepfer
  82.    _/_/ _/    _/        Schulstrasse 12
  83.   _/ _/_/    _/         CH-89262 Bergdietikon
  84.  _/   _/    _/ does it! patrick@schlaepferag.ch
  85.  
  86.  
  87.